package com.learn.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = {"/testa1", "/testb1"})
public class RequestMappingController {

    @RequestMapping(
            value = {"/testa2", "/testb2"}
//            method = {RequestMethod.GET, RequestMethod.POST} // 两个都能访问
//            method = {RequestMethod.GET} // 限制只能get请求
    )
    public String testRequestMapping() {
        return "success";
    }

    @GetMapping("/testGetMapping")
    public String testGetMapping() {
        return "success";
    }

    @RequestMapping(
            value = "/testPut",
            method = {RequestMethod.PUT}
    )
    public String testPut() {
        return "success";
    }

    @RequestMapping(
            value = {"/testParams"}
            , method = {RequestMethod.GET, RequestMethod.POST}
            , params = {"username", "password!=123456"}
    )
    public String testParams() {
        return "success";
    }

    @RequestMapping(
            value = {"/testHeaders"}
            , method = {RequestMethod.GET, RequestMethod.POST}
            , headers = {"Host=localhost:8080", "Connection222!=keep-alive"}
    )
    public String testHeaders() {
        return "success";
    }

    @RequestMapping("/a?a/testAnt")
    public String testAnt() {
        return "success";
    }

    @RequestMapping("/testPath/{id}/{username}")
    public String testPath(@PathVariable("id") String id, @PathVariable("username") String username) {
        System.out.println(String.format("id:%s,username:%s", id, username));
        return "success";
    }

}
